<?php

class SiteController extends Controller
{
	public $layout = 'main';
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex()
	{
		$this->pageTitle = 'hitewell 首页';
		$this->layout = 'index';
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		$this->render('index');
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionAboutus()
	{
		$this->pageTitle = '关于hitewell';
		$keyname = 'aboutus';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('aboutus',array('model'=>$model));
	}


	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionAq()
	{
		$this->pageTitle = 'hitewell 常见问题';
		$keyname = 'aq';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('aq',array('model'=>$model));
	}

	public function actionGroupintro()
	{
		$this->pageTitle = 'hitewell 集团介绍';
		$keyname = 'groupintro';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('groupintro',array('model'=>$model));
	}

	public function actionGroupqua()
	{
		$keyname = 'groupqua';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('groupqua',array('model'=>$model));
	}

	public function actionHitewellintro()
	{
		$keyname = 'hitewellintro';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('hitewellintro',array('model'=>$model));
	}

	public function actionGongsidongtaiB()
	{
		$this->pageTitle = 'hitewell 公司动态';
		$keyname = 'gongsidongtaiB';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('gongsidongtaib',array('model'=>$model));
	}

	public function actionChanpindongtaiB()
	{
		$this->pageTitle = 'hitewell 产品动态';
		$keyname = 'chanpindongtaiB';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('chanpindongtaib',array('model'=>$model));
	}

	public function actionQita()
	{
		
		$this->pageTitle = 'hitewell 其他';
		$keyname = 'qita';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('qita',array('model'=>$model));
	}

	public function actionDianli()
	{
		$this->pageTitle = 'hitewell 电力行业';
		$keyname = 'dianli';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('dianli',array('model'=>$model));
	}

	public function actionShihua()
	{
		$this->pageTitle = 'hitewell 石化';
		$keyname = 'shihua';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('shihua',array('model'=>$model));
	}

	public function actionShuichuli()
	{
		$this->pageTitle = 'hitewell 水处理';
		$keyname = 'shuichuli';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('shuichuli',array('model'=>$model));
	}

	public function actionLianyou()
	{
		$keyname = 'lianyou';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('lianyou',array('model'=>$model));
	}

	public function actionGangtie()
	{
		$this->pageTitle = 'hitewell 钢铁';
		$keyname = 'gangtie';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('gangtie',array('model'=>$model));
	}

	public function actionZaozhi()
	{
		$keyname = 'zaozhi';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('zaozhi',array('model'=>$model));
	}

	public function actionHedian()
	{
		$keyname = 'hedian';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('hedian',array('model'=>$model));
	}

	public function actionServicecenter()
	{
		$keyname = 'servicecenter';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('servicecenter',array('model'=>$model));
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionContactus()
	{
		$this->pageTitle = 'hitewell 联系我们';
		$keyname = 'contactus';
		Contenter::model()->ifexsit($keyname);
		$model = Contenter::model()->find("c_name='{$keyname}' and c_isdel = 1");
		$model = $model?$model:new Contenter;
		
		$this->render('contactus',array('model'=>$model));
	}


	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionSearch()
	{
		$this->pageTitle = 'hitewell 搜索';
		$this->layout = 'index';
		$models =array();
		if(isset($_GET['keyword'])&&$_GET['keyword']){
			$keyword = $_GET['keyword'];
			
			$models = Product::model()->findAllBySql("
				SELECT `p_id` as `p_produce`,`p_name`, 1 as p_isdel,p_updatetime FROM `hw_product`  where p_isdel = 1 and ( `p_name` regexp '{$keyword}' or `p_produce`  regexp '{$keyword}') union 
				SELECT `n_id`,`n_title`, 2 as p_isdel,n_updatetime FROM `hw_news` where n_isdel = 1 and (`n_title`  regexp '{$keyword}' or `n_content`  regexp '{$keyword}') union
				SELECT `z_id`,`z_title`, 3 as z_isdel,z_updatetime FROM `hw_zizhi` where z_isdel = 1 and (`z_title` regexp '{$keyword}' or `z_content` regexp '{$keyword}') union
				SELECT `s_id`,`s_title`, 5 as s_isdel,s_updatetime FROM `hw_servicecenter` where s_isdel = 1 and (`s_title` regexp '{$keyword}' or `s_content` regexp '{$keyword}') union
				SELECT `c_id`,`c_title`, 6 as c_isdel,c_updatetime FROM `hw_contactus` where c_isdel = 1 and (`c_title` regexp '{$keyword}' or `c_content` regexp '{$keyword}') union
				SELECT `c_name`,`c_value`,4 as p_isdel,c_updatetime FROM `hw_contenter` where c_isdel = 1 and  `c_value`  regexp '{$keyword}';
			");
		}
		$this->render('search',array('models'=>$models));
	}

	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError()
	{
		$this->pageTitle = '非法页面';
		$this->layout = 'index';
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}

	/**
	 * Displays the login page
	 */
	public function actionLogin()
	{
		$model=new LoginForm;

		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		$this->render('login',array('model'=>$model));
	}

	/**
	 * Logs out the current user and redirect to homepage.
	 */
	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
}